﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Users_MyOrder : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IDCard != null)
        {
            if (!Page.IsPostBack)
            {
                bindDTable();
            }
        }
    }
    private void bindDTable()
    {
        DataTable dt = Exam.getOrderInfosByIdCard(IDCard);
        if (dt.Columns.Contains("OrderStateCHN"))
            dt.Columns.Remove("OrderStateCHN");
        dt.Columns.Add("OrderStateCHN");
        foreach (DataRow dr in dt.Rows)
        {
            if (dr["OrderState"].ToString().Trim() == "0")
            {
                dr["OrderStateCHN"] = "未缴费";
            }
            else if (dr["OrderState"].ToString().Trim() == "5")
            {
                dr["OrderStateCHN"] = "缴费中";
            }
            else
            {
                dr["OrderStateCHN"] = "已缴费";
            }
        }

        gv.DataSource = dt;
        gv.DataBind();
    }

    protected void nextGoPay_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HyperLink hlNextGoPay = (HyperLink)e.Row.FindControl("nextGoPay");
            string orderState = gv.DataKeys[e.Row.RowIndex].Values[1].ToString().Trim();
            string orderId = gv.DataKeys[e.Row.RowIndex].Values[0].ToString().Trim();
            string sOrderId = security.EncryptQueryString(orderId.ToString());
            DataTable dt = Exam.getOrderInfoByOrderID(orderId);
            if (dt.Rows.Count > 0)
            {
                string emId = dt.Rows[0]["EmID"].ToString();
                string emYear = gv.DataKeys[e.Row.RowIndex].Values[2].ToString().Trim();
                string emNum = gv.DataKeys[e.Row.RowIndex].Values[3].ToString().Trim(); ;
                //获取考试报名时间,超时禁止修改
                DataTable dt_time = Exam.getEmTimeByEmId(emId, emYear, emNum);
                DataRow dr_time = dt_time.Rows[0];
                DateTime examBeginTime = DateTime.Parse(dr_time["ApplyBeginTime"].ToString());
                DateTime examEndTime = DateTime.Parse(dr_time["ApplyEndTime"].ToString().Trim());
                if (DateTime.Compare(DateTime.Now, examBeginTime) > 0 && DateTime.Compare(DateTime.Now, examEndTime.AddDays(1)) < 0)
                {
                    if (orderState == "0")
                    {
                        hlNextGoPay.NavigateUrl = BSUtility.mainUrl + "BM/BM4.aspx?OrderID=" + sOrderId;
                    }
                    else if (orderState == "5")
                    {

                        hlNextGoPay.NavigateUrl = BSUtility.mainUrl + "BM/BM4.aspx?OrderID=" + sOrderId;
                    }
                    else if (orderState == "9")
                    {
                        hlNextGoPay.Visible = false;
                    }
                }
                else
                {
                    hlNextGoPay.Visible = false;
                }
            }
            
            
        }
    }
}